package com.tanhua.server.controller;


import com.tanhua.commons.utils.JwtUtils;
import com.tanhua.model.db.UserInfo;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.UserService;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userService;


    /*
     * 请求方法 和请求链接  : POST /loginReginfo
     * 请求参数: UserInfo ,header
     * 返回值: 无
     * */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(
            @RequestBody UserInfo userInfo) {

        Long id = UserHolder.getUserId();
        userInfo.setId(id);

        userService.saveUserInfo(userInfo);
        return ResponseEntity.ok(null);

    }

    /*
    *  请求方式和请求链接: POST  /loginReginfo/head
    *  请求参数: Authorization, UserInfo
    *  返回值:无 ResponseEntity
    *
    * */
    @PostMapping("/loginReginfo/head")
    public ResponseEntity head(@RequestBody MultipartFile headPhoto) throws IOException {

        Long userId = UserHolder.getUserId();

        userService.updateUserInfo(userId,headPhoto);

        return ResponseEntity.ok(null);
    }
}
